Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Transition events order #1585

Closed
wants to merge 29 commits into from
Closed

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where the order of {before,after}{Enter,Leave} don't happen at the correct
time.

@vercel
Copy link

vercel bot commented Jun 13, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
headlessui-react ❌ Failed (Inspect) Aug 18, 2022 at 2:20PM (UTC)
headlessui-vue ✅ Ready (Inspect) Visit Preview Aug 18, 2022 at 2:20PM (UTC)

import { defer } from '../../utils/defer'

type TransitionDirection = 'enter' | 'leave' | 'idle'
let fakeDefer = () => defer<TransitionDirection>() // One day we will be able to do ReturnType<typeof genericFunction<T>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this already worked?

async function genericFunction<T>(foo: T): Promise<T> {
  return foo
}

type Cool<T> = ReturnType<typeof genericFunction<T>>
type A = Cool<"foo">

// A === Promise<"foo">

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As does this:

type Cool2 = ReturnType<typeof genericFunction<"bar">> // Cool2 === Promise<"bar">

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my editor disagrees 😅
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version we are on doesn't support this, but we can bump the version 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this causes other issues, let's tackle this in a different PR)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh interesting. I'm guessing VSCode isn't using the project version of typescript for checks like that for some reason

onStop.current(latestDirection.current)
},
[Reason.Cancelled]: () => {},
[Reason.Ended]: () => void onStop.current(latestDirection.current),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever use of void :D

leave: () => {
setState(TreeStates.Hidden)
unregister(id)
return events.current.afterLeave()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels so much better 🎉

@thecrypticace
Copy link
Contributor

So, so, so much better! I still think the order of the before events should be reversed (out -> in) but I know why they're not in React at least. Can you give this a try with Vue to make sure we match the order in both places (or I can port this if you want). I have a feeling, for some reason, that the order might already be reversed there if you implement this.

This will allow us to setup a promise that can be resolved or rejected
at a later point in time, deferred if you will.
We will prefer `onStart`, `onStop` instead, and handle the events in the
`Transition` component instead.
Also rely on the {before,after}[Enter,Leave] events instead of a `done`
function for unmounting which makes things simpler.
Always report that the current component is done.
Both return values are the same so there is no need to make them `void`.
# Conflicts:
#	packages/@headlessui-react/src/components/transitions/transition.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants